import Vue from 'vue';
import App from './App';
import router from './router';
import store from './store';
import './js/flexible.js';
import Request from '@/js/API/index.js';
import Common from '@/js/common.js';
import '@/package/index';
import ElementUI, { Loading } from 'element-ui';
import './css/index.scss';
import moment from 'moment';
import 'moment/locale/zh-cn';
import ECharts from 'vue-echarts';
import {use, graphic, registerMap} from 'echarts/core';
import {CanvasRenderer} from 'echarts/renderers';
import 'element-ui/lib/theme-chalk/index.css';
// import scroll from 'vue-seamless-scroll';
import 'echarts-liquidfill';
import {
  BarChart,
  LineChart, PieChart,
  ScatterChart,
  MapChart,
  RadarChart,
  EffectScatterChart,
  GaugeChart,
  FunnelChart,
  CustomChart,
  LinesChart
} from 'echarts/charts';
import {
  GridComponent,
  TooltipComponent,
  LegendComponent,
  VisualMapComponent,
  TitleComponent
} from 'echarts/components';
import './permission.js';
moment.locale('zh-cn');
use([
  CanvasRenderer,
  BarChart,
  LineChart,
  PieChart,
  ScatterChart,
  MapChart,
  RadarChart,
  EffectScatterChart,
  GaugeChart,
  GridComponent,
  TooltipComponent,
  LegendComponent,
  VisualMapComponent,
  TitleComponent,
  FunnelChart,
  CustomChart,
  LinesChart
]);
const loading = () => {
  const load = Loading.service({
    lock: true,
    text: '加载中...',
    background: 'rgba(0, 0, 0, 0.3)'
  });
  return load;
};

// vant组件
import vant from './vantUi/vant'
import 'vant/lib/index.css';
Vue.use(vant)

Vue.component('v-chart', ECharts);
// Vue.use(scroll);
Vue.use(ElementUI);
Vue.prototype.$loading = loading;
Vue.prototype.$graphic = graphic;
Vue.prototype.$registerMap = registerMap;
Vue.prototype.$moment = moment;
Vue.prototype.Request = Request;
Vue.prototype.Common = Common;
Vue.config.productionTip = false;

window.eventBus = new Vue();

// 从地址中获取token、projectId、productId、userId、mobile、userName
if(Common.getUrlArgument('?token')) sessionStorage.token = Common.getUrlArgument('?token');
if(Common.getUrlArgument('projectId')) sessionStorage.projectId = Common.getUrlArgument('projectId');
// if(Common.getUrlArgument('productId')) sessionStorage.setItem('productId', Common.getUrlArgument('productId'));
if(Common.getUrlArgument('userId')) sessionStorage.userId = Common.getUrlArgument('userId');
// if(Common.getUrlArgument('mobile')) sessionStorage.setItem('mobile', Common.getUrlArgument('mobile'));
if(Common.getUrlArgument('userName')) sessionStorage.userNameCopy = unescape(Common.getUrlArgument('userName')); // 中文解码
const searchParams = new URLSearchParams(window.location.href);
if(searchParams.get('userName')) {
  const userName = searchParams.get('userName');
  sessionStorage.userName = userName || 'nxin';
}

// 按钮权限限制自定义指令
import vPermission from './directtive/permission';
Vue.directive("permission", vPermission);

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
});
